import { objectAny } from "../../options/base";
import { mySchoolStore } from "../../store";
import { showModal } from "../utils";

const noticeManage = uniCloud.importObject(`admin-notice-manage`, {customUI: true});

export async function getNoticeList(
    justHome:boolean|undefined=false,
    whereId?:string|undefined
): Promise<Array<objectAny>> {
    const schoolStore = mySchoolStore();
    // 赋值本地的所属学校ID
    const schoolId=schoolStore.mySchool._id;

    try {
        const {
            myErrCode,
            errMsg,
            data
        }=await noticeManage.getNoticeList(schoolId,justHome,whereId);
        if (myErrCode !== 0) {
            showModal({
                title: `异常提示`,
                content: errMsg,
                showCancel: false
            })
            return []
        }

        return data;
    } catch (error) {
        console.log(`xxxxxx=>  getNoticeList 获取通知列表数据异常，异常信息如下： <=xxxxxx`)
        console.error(error)
    }
    return []
}